@@ -13,7 +13,7 @@ module Agents |
||
| 13 | 13 |
You can implement `Agent.check` and `Agent.receive` as you see fit. The following methods will be available on Agent in the JavaScript environment: |
| 14 | 14 |
|
| 15 | 15 |
* `this.createEvent(payload)` |
| 16 |
- * `this.incomingEvents()` |
|
| 16 |
+ * `this.incomingEvents()` (the returned event objects will each have a `payload` property) |
|
| 17 | 17 |
* `this.memory()` |
| 18 | 18 |
* `this.memory(key)` |
| 19 | 19 |
* `this.memory(keyToSet, valueToSet)` |
@@ -16,6 +16,9 @@ class Event < ActiveRecord::Base |
||
| 16 | 16 |
belongs_to :user |
| 17 | 17 |
belongs_to :agent, :counter_cache => true, :touch => :last_event_at |
| 18 | 18 |
|
| 19 |
+ has_many :agent_logs_as_inbound_event, :class_name => "AgentLog", :foreign_key => :inbound_event_id, :dependent => :nullify |
|
| 20 |
+ has_many :agent_logs_as_outbound_event, :class_name => "AgentLog", :foreign_key => :outbound_event_id, :dependent => :nullify |
|
| 21 |
+ |
|
| 19 | 22 |
scope :recent, lambda { |timespan = 12.hours.ago|
|
| 20 | 23 |
where("events.created_at > ?", timespan)
|
| 21 | 24 |
} |
@@ -36,6 +39,7 @@ class Event < ActiveRecord::Base |
||
| 36 | 39 |
end |
| 37 | 40 |
|
| 38 | 41 |
protected |
| 42 |
+ |
|
| 39 | 43 |
def possibly_propagate |
| 40 | 44 |
#immediately schedule agents that want immediate updates |
| 41 | 45 |
propagate_ids = agent.receivers.where(:propagate_immediately => true).pluck(:id) |
@@ -1,9 +1,11 @@ |
||
| 1 | 1 |
log_for_jane_website_agent: |
| 2 | 2 |
agent: jane_website_agent |
| 3 |
+ outbound_event: jane_website_agent_event |
|
| 3 | 4 |
message: "fetching some website data" |
| 4 | 5 |
|
| 5 | 6 |
log_for_bob_website_agent: |
| 6 | 7 |
agent: bob_website_agent |
| 8 |
+ outbound_event: bob_website_agent_event |
|
| 7 | 9 |
message: "fetching some other website data" |
| 8 | 10 |
|
| 9 | 11 |
first_log_for_bob_weather_agent: |
@@ -75,6 +75,18 @@ describe Event do |
||
| 75 | 75 |
Event.find_by_id(event.id).should_not be_nil |
| 76 | 76 |
end |
| 77 | 77 |
end |
| 78 |
+ |
|
| 79 |
+ describe "after destroy" do |
|
| 80 |
+ it "nullifies any dependent AgentLogs" do |
|
| 81 |
+ agent_logs(:log_for_jane_website_agent).outbound_event_id.should be_present |
|
| 82 |
+ agent_logs(:log_for_bob_website_agent).outbound_event_id.should be_present |
|
| 83 |
+ |
|
| 84 |
+ agent_logs(:log_for_bob_website_agent).outbound_event.destroy |
|
| 85 |
+ |
|
| 86 |
+ agent_logs(:log_for_jane_website_agent).reload.outbound_event_id.should be_present |
|
| 87 |
+ agent_logs(:log_for_bob_website_agent).reload.outbound_event_id.should be_nil |
|
| 88 |
+ end |
|
| 89 |
+ end |
|
| 78 | 90 |
end |
| 79 | 91 |
|
| 80 | 92 |
describe EventDrop do |